package cn.edu.zafu.bigdata.x.zzzznnn.d;

public class ArrayIndexOutOfBounds{
    public static int getElement(int[] arr, int index) {
        if (index < 0 || index >= arr.length) {
            throw new ArrayIndexOutOfBoundsException("索引超出数组范围");
        }
        return arr[index];
    }

    public static void main(String[] args) {
        int[] array = {1, 2, 3};
        try {
            int element = getElement(array, 5);
            System.out.println("元素为：" + element);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("发生错误：" + e.getMessage());
        }
    }
}
